package ee.fj.util.assertion;

import java.util.logging.Logger;

import ee.fj.util.ReflectionHelper;

public class FieldAssertion extends Assertion {
	public static final Logger log = Logger.getLogger(FieldAssertion.class.getName());
	private final String field;
	private final Assertion condition;

	public FieldAssertion(String field, Assertion condition, boolean reverse) {
		super(reverse);
		this.field = field;
		this.condition = condition;
	}

	public FieldAssertion(String field, Assertion condition) {
		this(field, condition, DEFAULT_CONDITION);
	}

	@Override
	protected boolean satisfiesInner(Object value) throws AssertionException {
		try {
			Object val = ReflectionHelper.getValue(value, field);
			return condition.satisfies(val);
		} catch (NoSuchFieldException e) {
			throw new AssertionException(e);
		}
	}

}